package com.mrd.gtimp.base.entity;

import org.hibernate.annotations.GenericGenerator;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Transient;

/**
 * <p> application name: gtimp <p> copyright: Copyright@2012 明睿达科技有限公司
 */

/**
 * 权限对象
 *
 * @author qiul
 */
@Entity(name = "T_SYS_PERMISSIONS")
public class Permissions implements Serializable, Comparable<Permissions> {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(generator = "buttonGenerator")
    @GenericGenerator(name = "buttonGenerator", strategy = "uuid")
    @Column(name = "ID")
    private String id;

    /**
     * 权限名称
     */
    @Column(name = "name", nullable = true)
    private String name;

    /**
     * 权限类型
     */
    @Column(name = "p_type")
    private String type;
    // @ManyToOne
    // @JoinColumn(referencedColumnName = "B_IDENTIFIER", name = "p_type")
    // private SystemValue type;

    /**
     * 权限标识
     */
    @Column(name = "pid", nullable = true)
    private String pid;

    /**
     * 按钮id
     */
    @Column(name = "bt_id")
    private String buttonId;

    /**
     * 按钮的显示值
     */
    @Column(name = "bt_label")
    private String label;

    /**
     * 按钮触发事件
     */
    @Column(name = "bt_click")
    private String click;

    /**
     * 是否显示
     */
    @Column(name = "hidden")
    private String hidden = "0";

    /**
     * 是否启用
     */
    @Column(name = "disable")
    private String disable = "0";

    /**
     * 所属模块
     */
    @ManyToOne
    @JoinColumn(name = "module_id", referencedColumnName = "id")
    private Module module;
    /**
     * 是否被选择，临时字段
     */
    @Transient
    private boolean checked;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    public String getClick() {
        return click;
    }

    public void setClick(String click) {
        this.click = click;
    }

    public String getHidden() {
        return hidden;
    }

    public void setHidden(String hidden) {
        this.hidden = hidden;
    }

    public String getButtonId() {
        return buttonId;
    }

    public void setButtonId(String buttonId) {
        this.buttonId = buttonId;
    }

    public String getDisable() {
        return disable;
    }

    public void setDisable(String disable) {
        this.disable = disable;
    }

    public Module getModule() {
        return module;
    }

    public void setModule(Module module) {
        this.module = module;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getPid() {
        return pid;
    }

    public void setPid(String pid) {
        this.pid = pid;
    }

    public boolean getChecked() {
        return checked;
    }

    public void setChecked(boolean checked) {
        this.checked = checked;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((id == null) ? 0 : id.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        Permissions other = (Permissions) obj;
        if (id == null) {
            if (other.id != null)
                return false;
        } else if (!id.equals(other.id))
            return false;
        return true;
    }

    /*
     * (non-Javadoc)
     * @see java.lang.Comparable#compareTo(java.lang.Object)
     */
    @Override
    public int compareTo(Permissions o) {
        int i = 0;
        if (o.name == null) {
            i = 1;
        } else if (this.name == null) {
            i = -1;
        } else {
            i = this.name.compareTo(o.name);
        }
        if (i == 0) {
            i = this.id.compareTo(o.id);
        }
        return i;
    }

    @Override
    public String toString() {
        return "Permissions [id=" + id + ", name=" + name + ", type=" + type + ", pid=" + pid
                + ", label=" + label + ", module=" + module.getName() + "]";
    }

    // public SystemValue getType() {
    // return type;
    // }
    //
    // public void setType(SystemValue type) {
    // this.type = type;
    // }

}
